//
//  SexView.m
//  EducationAdminClient
//
//  Created by kwsdzjx on 15/12/5.
//  Copyright © 2015年 周佳兴. All rights reserved.
//

#import "SexView.h"
#import "MyButton2.h"
#import "Masonry.h"

@implementation SexView

-(id)initWithBlock:(void (^)(NSString *))cb {
    _cb = cb;
    self = [super init];
    if (self) {
        [self createUI];
        self.hidden = YES;
    }
    return self;
}
//- (instancetype)init
//{
//    self = [super init];
//    if (self) {
//        [self createUI];
//    }
//    return self;
//}

-(void)createUI{
    MyButton2 *girlBtn = [[MyButton2 alloc]init];
    [self addSubview:girlBtn];
    
    MyButton2 *boyBtn = [[MyButton2 alloc]init];
    [self addSubview:boyBtn];
    
    [girlBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_centerX).offset(-20);
        make.centerY.equalTo(self.mas_centerY).offset(30);
        make.width.equalTo(@(50));
        make.height.equalTo(@(30));
    }];
    
    [boyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_centerX).offset(20);
        make.centerY.equalTo(girlBtn.mas_centerY);
        make.width.equalTo(@(50));
        make.height.equalTo(@(30));
    }];

    
    girlBtn.Btntag = 0;
    boyBtn.Btntag = 1;
    [girlBtn setTitle:@"女" forState:UIControlStateNormal];
    [boyBtn setTitle:@"男" forState:UIControlStateNormal];
    [girlBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [boyBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [girlBtn addTarget:self action:@selector(sexBtn:) forControlEvents:UIControlEventTouchUpInside];
    [boyBtn addTarget:self action:@selector(sexBtn:) forControlEvents:UIControlEventTouchUpInside];

    
#warning change the img while UI used
    [girlBtn setImage:[UIImage imageNamed:@"椭圆-1-拷贝-3"] forState:UIControlStateNormal];
    [girlBtn setImage:[UIImage imageNamed:@"形状-20-拷贝"] forState:UIControlStateSelected];

    [boyBtn setImage:[UIImage imageNamed:@"椭圆-1-拷贝-3"] forState:UIControlStateNormal];
    [boyBtn setImage:[UIImage imageNamed:@"形状-20-拷贝"] forState:UIControlStateSelected];

    UIButton *cancelButton = [[UIButton alloc]init];
    //    cancelButton.backgroundColor = [UIColor blackColor];
    [self addSubview:cancelButton];
    [cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY);
        make.left.equalTo(self.mas_left).offset(32/2);
        //        make.right.equalTo(withShowPicView.mas_right);
        make.height.equalTo(@(48/2));
    }];
    [cancelButton setImage:[UIImage imageNamed:@"cancelNbUTTON"] forState:UIControlStateNormal];
    [cancelButton setImage:[UIImage imageNamed:@"cancelButton"] forState:UIControlStateSelected];
    UILabel *centerLabel = [[UILabel alloc]init];
    [self addSubview:centerLabel];
    [centerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(cancelButton.mas_centerY);
        make.centerX.equalTo(self.mas_centerX);
        //        make.right.equalTo(withShowPicView.mas_right);
        //        make.height.equalTo(@(48/2));
    }];
    
    
    centerLabel.font = [UIFont systemFontOfSize:32/2];
    centerLabel.text = @"性别";
    centerLabel.textColor = [UIColor colorWithRed:0x74/255.0 green:0x75/255.0 blue:0x79/255.0 alpha:1];
    UIButton *okButton = [[UIButton alloc]init];
    [self addSubview:okButton];
    [okButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(cancelButton.mas_centerY);
        make.right.equalTo(self.mas_right).offset(-32/2);
        //        make.right.equalTo(withShowPicView.mas_right);
        make.height.equalTo(@(48/2));
    }];
    [cancelButton addTarget:self action:@selector(cancelClick) forControlEvents:UIControlEventTouchUpInside];
    [okButton addTarget:self action:@selector(okClick) forControlEvents:UIControlEventTouchUpInside];
    [okButton setImage:[UIImage imageNamed:@"okNButton"] forState:UIControlStateNormal];
    [okButton setImage:[UIImage imageNamed:@"okButotn"] forState:UIControlStateSelected];
//    cancelButton.backgroundColor = [UIColor blackColor];
//    okButton.backgroundColor = [UIColor orangeColor];

}

-(void)cancelClick{
    self.hidden = YES;
}

-(void)okClick{
    
    if(_currentBtn!=nil&&_currentBtn.Btntag == 0){
        _cb(@"女");
    }else if(_currentBtn!=nil){
        _cb(@"男");
    }
    if(_currentBtn!=nil)_currentBtn.selected = NO;
    _currentBtn = nil;
    self.hidden = YES;
}
-(void)sexBtn:(MyButton2 *)btn{
    if(_currentBtn!=nil)_currentBtn.selected = NO;
    _currentBtn = btn;
    btn.selected = YES;
}
@end
